package erfgame.frontend.desktop.view.terrain.iso.interaction.position;

import erfgame.core.Point3D;
import erfgame.core.Rectangle3D;
import erfgame.core.world.World;
import erfgame.core.world.terrain.TerrainUpdate;
import erfgame.core.world.terrain.TerrainUpdateGroup;

public class TileCenterLayerBottomTerrainUpdatePositionFactory extends
		TileCenterLayerTopTerrainUpdatePositionFactory {
	
	public TileCenterLayerBottomTerrainUpdatePositionFactory() {
		
	}
	
	public TileCenterLayerBottomTerrainUpdatePositionFactory( int granularity ) {
		super( granularity );
	}

	@Override
	public int getZ(Point3D terrain, TerrainUpdateGroup terrainUpdate, World world) {
		int depthMult = world.getBlockDepth() * blockGranularity; 
		Rectangle3D bounds = terrainUpdate.getBounds(); 
		int z = Math.max( 0, ((terrain.z-1) / depthMult) + 1 ) * depthMult - bounds.minZ - bounds.getDepth();
		return z;
		
	}
}
